<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateGoldRecordsTable extends Migration
{
    public function up()
    {
        Schema::create('gold_records', function (Blueprint $table) {
            $table->id();
	        $table->unsignedBigInteger('user_id')->default(0)->index();
	        $table->unsignedBigInteger('gold_seed_id')->default(0)->index();
	        $table->unsignedBigInteger('gold_round_id')->default(0)->index();
	        $table->unsignedBigInteger('gold_product_id')->default(0)->index();
	        $table->unsignedBigInteger('product_id')->default(0)->index();
	        $table->unsignedBigInteger('product_sku_id')->default(0)->index();
	        $table->unsignedBigInteger('up_gold_record_id')->default(0)->index()->comment('resold from gold record');
	        $table->unsignedInteger('round')->default(0);
	        $table->string('gold_seed_title')->nullable();
	        $table->string('product_title')->nullable();
	        $table->string('product_cover')->nullable();
	        $table->string('sku_name')->nullable();
	        $table->string('sku_pic')->nullable();
	        $table->string('sku_attr_value_index')->nullable();
	        $table->text('sku_attr_value')->nullable();

	        $table->decimal('record_all_price', 10, 2)->default(0);
	        $table->decimal('resell_all_price', 10, 2)->default(0);

	        $table->decimal('pay_net_price', 10, 2)->default(0);
	        $table->decimal('pay_cash_price', 10, 2)->default(0);
	        $table->decimal('pay_gold_beans', 10, 2)->default(0);
	        $table->decimal('profit_after_resold', 10, 2)->default(0);

	        $table->dateTime('closed_at')->nullable();
	        $table->dateTime('paid_at')->nullable();
	        $table->string('paid_method')->nullable();

	        $table->dateTime('to_resell_applied_at')->nullable();
	        $table->dateTime('to_split_applied_at')->nullable();
	        $table->dateTime('to_take_applied_at')->nullable();

	        $table->dateTime('settled_at')->nullable()->index()->comment('settle up record reselling or split money');
	        $table->dateTime('rewarded_at')->nullable()->index();
	        $table->dateTime('finished_at')->nullable()->index();

	        $table->softDeletes();
	        $table->timestamps();

	        $table->index(['created_at']);
        });
    }

    public function down()
    {
        Schema::dropIfExists('gold_records');
    }
}
